//
//  MXFindBlockTypeTwoTableViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/15.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXFindBlockTypeTwoTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation MXFindBlockTypeTwoTableViewCell
- (void)dealloc
{
    [_mainImageView release];
    [_priceLabel release];
    [_detailLabel release];
    [_model release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.mainImageView = [[[UIImageView alloc ]init] autorelease];
//        self.mainImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.mainImageView];
        
        self.priceLabel = [[[UILabel alloc] init] autorelease];
//        self.priceLabel.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:self.priceLabel];
        
        self.detailLabel = [[[UILabel alloc ]init] autorelease];
//        self.detailLabel.backgroundColor = [UIColor yellowColor];
        self.detailLabel.font = [UIFont systemFontOfSize:12];
        self.detailLabel.numberOfLines = 0;
        [self.contentView addSubview:self.detailLabel];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat mainImageViewX = WIDTHPRO * 10;
    CGFloat mainImageViewY = HEIGHTPRO * 10;
    CGFloat mainImageViewW = WIDTHPRO * 80;
    CGFloat mainImageViewH = mainImageViewW;
    self.mainImageView.frame = CGRectMake(mainImageViewX, mainImageViewY, mainImageViewW, mainImageViewH);
    
    CGFloat priceLabelX = mainImageViewW + mainImageViewX + WIDTHPRO * 10;
    CGFloat priceLabelY = mainImageViewY;
    CGFloat priceLabelW = WIDTHPRO * 200;
    CGFloat priceLabelH = HEIGHTPRO * 30;
    self.priceLabel.frame = CGRectMake(priceLabelX, priceLabelY, priceLabelW, priceLabelH);
    
    CGFloat detailLabelX = priceLabelX;
    CGFloat detailLabelY = priceLabelY + priceLabelH;
    CGFloat detailLabelW = self.frame.size.width - mainImageViewX - mainImageViewW - WIDTHPRO * 20;
    CGFloat detailLabelH = mainImageViewH - priceLabelH;
    self.detailLabel.frame = CGRectMake(detailLabelX, detailLabelY, detailLabelW, detailLabelH);
    
}


- (void)getInfo:(MXFindDetailModel *)model rowNum:(NSInteger)rowNum
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    NSMutableArray *imageArr = [NSMutableArray array];
    NSMutableArray *priceArr = [NSMutableArray array];
    NSMutableArray *detailArr = [NSMutableArray array];
    for (NSDictionary *dict in model.product) {
        [imageArr addObject:[dict objectForKey:@"img"]];
        
        [priceArr addObject:[dict objectForKey:@"title"]];
        
        [detailArr addObject:[dict objectForKey:@"detail"]];
    }
    
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:imageArr[rowNum]] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.priceLabel.text = priceArr[rowNum];
    
    self.detailLabel.text = detailArr[rowNum];
    
    
    

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
